<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>计算输入框修改的次数</title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <div>
            <input type="text" ng-model="name" placeholder="请输入姓名">
        </div>
        <div>累计变化次数：{{count}}</div>
    </div>

    <script>
        var app = angular.module('app',[]);
        app.controller('cont',['$scope',function ($scope) {
            $scope.count = 0;
            $scope.name = '';
            $scope.$watch('name',function () {
                $scope.count++;
            })
        }])

    </script>
</body>
</html>